package com.wkr.springbootquartz.controller;

import com.wkr.springbootquartz.manager.QuartzManager;
import com.wkr.springbootquartz.task.Task;
import com.wkr.springbootquartz.task.Task2;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: wukangrong
 * @date: 2020/6/30 14:00
 * @description:
 */
@RestController
public class Controller {
    static int id = 0;


    @Autowired
    QuartzManager quartzManager;

    @GetMapping("/task1")
    public void task1() {
        String cron = "0/2 * * * * ?";
        quartzManager.addJob(new Task(), "task1", "group1", cron);
    }

    @GetMapping("/update")
    public void update() {
        quartzManager.pauseJobs("task1", "group1");
        quartzManager.updatCronExpression("task1", "group1", "0/5 * * * * ?");
    }
    @GetMapping("/task2")
    public void task2() {
        quartzManager.addJob(new Task2(), "task2", "group2", "0/3 * * * * ?");
    }

    @GetMapping("/query")
    public void query() throws SchedulerException {
        quartzManager.queryJobs();
    }

    //10.192.33.98:8080/quartz/pause?jobName=task1&groupName=group1

    @GetMapping("/pause")
    public void pause(@RequestParam String jobName, @RequestParam String groupName){
        quartzManager.pauseJobs(jobName, groupName);
    }
}
